# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=emacs-plz
pkgver=0.8
pkgrel=0
_pkgreal=plz
pkgdesc="HTTP library with curl as backend"
url="https://github.com/alphapapa/plz.el"
arch="noarch"
license="GPL-3.0-or-later"
depends="cmd:curl cmd:emacs"
makedepends="emacs-nox"
source="https://github.com/alphapapa/plz.el/archive/v$pkgver/emacs-plz-$pkgver.tar.gz"
builddir="$srcdir/plz.el-$pkgver"
options="net" # tests access httpbin.org

build() {
	emacs -batch -q -no-site-file -L . \
		-eval '(setq byte-compile-error-on-warn t)' \
		-f batch-byte-compile \
		./*.el
}

check() {
	# Tests may fail due to network issues, try to repeat 3 times.
	local i; for i in $(seq 0 3); do
		[ $i -eq 0 ] || msg "Retrying ($i/3)..."
		emacs -batch -q -no-site-file -L . -L tests -l test-plz \
			-eval '(setq plz-test-uri-prefix "https://httpbin.org")' \
			-f ert-run-tests-batch-and-exit && return 0
		sleep 1
	done
	return 1
}

package() {
	install -Dvm644 ./*.el ./*.elc \
		-t "$pkgdir"/usr/share/emacs/site-lisp/plz/

	cd "$pkgdir"/usr/share/emacs/site-lisp/plz
	emacs -batch -q -no-site-file \
		-eval "(loaddefs-generate \".\" \"$_pkgreal-loaddefs.el\")"
}

sha512sums="
8d5c4eaadc863a8cb356616717fa976e7785a5a1d4c91baf9fbfcf9a0c054a7afa25c26e4e3673e484b2206b140fe77047a041ee0596812802d7a0f12e3c0c45  emacs-plz-0.8.tar.gz
"
